package com.bw.a2207a

import android.app.Activity
import android.widget.Toast
import com.blankj.utilcode.util.ToastUtils

/**
 *
 * @ClassName: Test
 * @Description: java类作用描述
 * @Author: zhangyanchao
 * @CreateDate: 2024/10/15 11:20 AM
 * @Version: 1.0
 */
fun main() {
//    sum(1, 2)
    val list = listOf<Int>(1, 2, 3)
    sumOfEven(list)


//
    val a = 10
    val b = 20
    print(a + b)

//    list.forEach() {
//        if (it > 10) {
//            print(it)
//        }
//    }

    //滤出所有大于10的数字并输出
    val list2 = list.filter { it > 10 }
    list2.forEach() {
        print(it)
    }

    list2.forEachIndexed { index, i ->
        print(i)
    }

    changeName()
    print(name)
}

inline fun sum(a: Int, b: Int): Int {
    print(2)
    return a + b
}

val list = listOf<Int>(1, 2, 3)


fun sumOfEven(l: List<Int>) {
    var num = 0
    l.forEach() {
        if (it % 2 == 0) {
            //偶数相加
            //num = it + num
            num += it
        } else {
            //把奇数输出
            print(it)
        }
    }
    print(num)
}


var name = "abc"

fun changeName() {
    name = "cdf"
}

//定义一个扩展函数
fun Activity.showToastMsg(msg:String){
    //ToastUtils.showShort(msg)
    Toast.makeText(this,msg,Toast.LENGTH_SHORT).show()
}



